package thread.Euecutors;

import java.sql.Time;
import java.util.concurrent.*;

public class EuecutorsTest  {


    public static void main(String[] args) {

        /**
         * 创建固定大小的线程池
         */
        ExecutorService executorService = Executors.newFixedThreadPool(10);

        executorService.execute(()->{
            System.out.println(Thread.currentThread().getName());
        });


        ExecutorService executorService1 = Executors.newCachedThreadPool();
        executorService1.execute(()->{
            System.out.println(Thread.currentThread().getName()+":创建缓存线程池");

        });

        /**
         * 创建单线程池
         */
        ExecutorService executorService2 = Executors.newSingleThreadExecutor();
        executorService2.execute(()->{
            System.out.println(Thread.currentThread().getName()+":创建单线程池");
        });

        ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);
        scheduledExecutorService.scheduleWithFixedDelay(()->{
            System.out.println(Thread.currentThread().getName()+":创建周期性线程池");
        },1,1, TimeUnit.SECONDS);


        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(),new ThreadPoolExecutor.CallerRunsPolicy());
        threadPoolExecutor.execute(()->{
            System.out.println(Thread.currentThread().getName());
        });
    }

}
